package com.sri.controller.login;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.sri.business.login.LoginManager;
import com.sri.cache.CacheManager;
import com.sri.formBeans.LoginForm;

/**
 * @author skodali
 * 
 */
public class LoginAction extends DispatchAction {

	Logger logger = LogManager.getLogger("LoginAction");

	/**
	 * Method execute
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	/*
	 * public ActionForward execute(ActionMapping mapping, ActionForm form,
	 * HttpServletRequest request, HttpServletResponse response) {
	 * System.out.println("*** execute ***");
	 * 
	 * return super.execute(mapping, form, request, response); }
	 */

	/**
	 * Method login
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward login(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		System.out.println("Login");
		logger.debug("Login");
		LoginForm logingForm = (LoginForm) form;
		if (LoginManager.login(logingForm)) {
			request.setAttribute("stateCities", CacheManager
					.getCitiesByStateId(2));
			return mapping.findForward("success");
		}
		return mapping.findForward("failure");
	}

	/*
	 * public ActionForward execute(ActionMapping mapping, ActionForm form,
	 * HttpServletRequest request, HttpServletResponse response) {
	 * System.out.println("execute"); logger.debug("execute");
	 * LoginManager.login(); return mapping.findForward("success"); }
	 */

}
